
/**

Debates and Partisan Divisions in Malawi
Comparative Political Studies

Eric Kramon
07 June 2023

This file produces all tables and figuresin the paper

This file was created and run in Stata/IC 15.1
**/
 
 
set more off 
 
*********************************
** Set to working directory where data is saved

cd "~/Dropbox/Malawi/"


************************************
** Create folder to store output

* only need to run this once
capture mkdir "output"

*****************************************
** Input data 

use malawiCPSreplication.dta, clear


** Set Pre-treatment control variables to be used in all analyses
global Xs female age ed_cat employed assets pre_debate


***************************************************************
** Figure 1 Support for Major Parties as of April 2019

** Figure created elsewhere using these numbers

tab partisan

***************************************************************
** Figure 2 summarizes the research process and timeline

***************************************************************
** Table 1 displays the district and regions in the country


***************************************************************
** Table 2 -- Samples sizes in each experimental condition

** Row 1, columns A and B, and F
tab T

*Row 1, columns C, D, E
tab condition 

** Row 2, columns A and B, and F 
	*(only postelectoin survey participants with outcomes data)
 tab T if wave2==1  & vote_w2_1!=.

 *Row 2, columns C, D, E
tab condition if wave2==1  & vote_w2_1!=.

***************************************************************
** Table 3 displays survey questions for main outcome variables



***************************************************************
** Figure 3	Cross party voting rates in treatment and control


graph bar cross_party_vote_w1 , over(T) bar(1, color(gs10)) bar(2, color(gs5)) ///
		graphr(color(white)) ///
	 ylabel(, angle(horizontal)) ///
	 title("Vote Intention After Debate",  size(medium) color(black))  ///
	  ytitle("% Voting Across Party Lines")	 label name(a, replace) blabel(bar, format(%3.2f))

	  
graph bar cross_party_vote_w2 if wave2==1, over(T) bar(1, color(gs10)) bar(2, color(gs5)) ///
		graphr(color(white)) ///
	 ylabel(, angle(horizontal)) ///
	 title("Vote Choice in Election", size(medium) color(black))  ///
	  ytitle("% Voting Across Party Lines")	 label name(b, replace) blabel(bar, format(%3.2f))

graph combine a b, ycommon	   graphr(color(white)) 

graph export output/figure3.pdf, as(pdf) replace

** Altnerative -- want to show error bars

regress cross_party_vote_w1 T
	margins, at(T=0 T=1)
	marginsplot, graphr(color(white)) ///
			title("Vote Intention After Debate",  size(medium) color(black))  ///
			ytitle("% Voting Across Party Lines")	 name(a, replace) ///
			xtitle(" ") xscale(range(-.5 1.5)) ///
				 ylabel(, angle(horizontal)) ///
				 recast(scatter) 

regress cross_party_vote_w2 T if wave2==1
	margins, at(T=0 T=1)
	marginsplot, graphr(color(white)) ///
			title("Vote Choice in Election",  size(medium) color(black))  ///
			ytitle("% Voting Across Party Lines")	 name(b, replace) ///
			xtitle(" ") xscale(range(-.5 1.5)) ///
				 ylabel(, angle(horizontal)) ///
				 recast(scatter)				 


graph combine a b, ycommon	   graphr(color(white)) 

graph export output/figure3.pdf, as(pdf) replace

				 
***************************************************************
**Table 4 Treatment effects on cross-party voting
	* EA fixed effects + pre-specified controls
	
areg cross_party_vote_w1 T $Xs if independent==0,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	outreg2 using output/table4.tex, ///
	ctitle("After Debate", "All") tex(fra) label replace dec(2) ///
	keep(T Ag_T Ed_T  HC_T) sortvar(T Ag_T Ed_T  HC_T) 

	
areg cross_party_vote_w1 T $Xs if  wave2==1,  absorb(ea_numeric)
	outreg2 using output/table4.tex, ///
	ctitle("After Debate", "Panel Sample") ///
	tex(fra) label append dec(2) ///
	keep(T Ag_T Ed_T  HC_T) sortvar(T Ag_T Ed_T  HC_T) 

areg cross_party_vote_w2 T $Xs  if  wave2==1,  absorb(ea_numeric)
	outreg2 using output/table4.tex, ///
	ctitle("After Election", "Panel Sample") tex(fra) ///
	label append dec(2) ///
	keep(T Ag_T Ed_T  HC_T) sortvar(T Ag_T Ed_T  HC_T)  

	
areg cross_party_vote_w1 Ag_T Ed_T  HC_T $Xs ,  absorb(ea_numeric)
	outreg2 using output/table4.tex, ///
	ctitle("After Debate", "All") ///
	tex(fra) label append dec(2) ///
	keep(T Ag_T Ed_T  HC_T) sortvar(T Ag_T Ed_T  HC_T) 	

areg cross_party_vote_w2 Ag_T Ed_T  HC_T $Xs  if  wave2==1,  absorb(ea_numeric)
	outreg2 using output/table4.tex, ///
	ctitle("After Election", "Panel Sample") tex(fra) ///
	label append dec(2) ///
	keep(T Ag_T Ed_T  HC_T) sortvar(T Ag_T Ed_T  HC_T)	
	

***********************************************************
** Table 5: treatment effects on evaulations	
	
* This requires the data in long (not wide) format

* Preserve data
tempfile wide
save `wide'

** Transform to long

** Create list of variables for transformation
local stub evalpost_w1_ evalpost_w2_ vote_w1_ vote_w2_ coethnic_w1_ coethnic_w2_ coethnic_ea_ close_ evaluation_ prior_  ///
	winner_all_ winner_district_ winner_expert_ performance_ performance_district_   ///
	confidence_w1_ confidence_w2_ str_policy_w1_ str_policy_w2_ qualified_w1_ qualified_w2_  ///
	trust_w1_ trust_w2_ incumbent_  prior_diff_dist_ goodnews_ ///
	danger_ reason_w1_ reason_w2_ campaign_ ea_close_ ea_close_majority_ friends_prop_ ///
	quota_agree_ fisp_agree_ immunity_agree_  
	

capture drop id
gen id = _n

reshape long `stub' , i(id) j(candidate)

gen party = "dpp" if candidate==1
replace party = "mcp" if candidate==2
replace party = "udf" if candidate==3
replace party = "utm" if candidate==4

label variable close_ "Partisan"
label define close_ 0 "Out-Partisan" 1 "Co-Partisan"
label values close_ close_

** Average, out-partisans
areg evalpost_w1_ T $Xs if close_==0&independent==0, vce(cluster id) absorb(ea_numeric)
	outreg2 using output/table5.tex, ///
	ctitle("After Debate", "Out-Partisans") tex(fra) ///
	label replace dec(2) keep(T) 

** Average co-partisans
areg evalpost_w1_ T $Xs if close_==1&independent==0, vce(cluster id) absorb(ea_numeric)
outreg2 using output/table5.tex, ///
	ctitle("After Debate", "Co-Partisans") tex(fra) ///
	label append dec(2) keep(T)

** Average, out-partisans
areg evalpost_w2_ T $Xs if close_==0&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
outreg2 using output/table5.tex, ///
	ctitle("After Election", "Out-Partisans") tex(fra) ///
	label append dec(2) keep(T)

	** Average co-partisans
areg evalpost_w2_ T $Xs if close_==1&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
outreg2 using output/table5.tex, ///
	ctitle("After Election", "Co-Partisans") tex(fra) ///
	label append dec(2) keep(T)	


** Re-open wide data

use `wide', clear
		
	
***********************************************************************
** Figure 4 treatment effects on cross-party voting by partisan groups

areg cross_party_vote_w1 T $Xs if dpp_close==1,  absorb(ea_numeric)
	est sto a

areg cross_party_vote_w1 T $Xs if mcp_close==1,  absorb(ea_numeric)
	est sto b
		
areg cross_party_vote_w1 T $Xs if udf_close==1,  absorb(ea_numeric)
	est sto c
		
areg cross_party_vote_w1 T $Xs if utm_close==1,  absorb(ea_numeric)
	est sto d


		
local x "mcolor(black)  ciopts(color(black))  offset(0)"
coefplot (a, `x' label(DPP Supporters) aseq("DPP Supporters (N=561)")) (b,`x' label(MCP Supporters) aseq("MCP Supporters (N=337)")) ///
	(c, `x' label(UDF Supporters) aseq("UDF Supporters (N=58)")) (d,  `x' label(UTM Supporters) aseq("UTM Supporters (N=270)"))	, ///
	keep(T) aseq swapnames ///
	graphr(color(white)) ytitle("", size(medsmall)) ///
	 ylabel(, labsize(medsmall) angle(horizontal)) xlabel(-.5(.1).5, labsize(medsmall)) ///
	 name(v1, replace) xtitle("Effect on Cross-Party Vote Intention", size(medsmall))    ///
	  levels(95) xline(0, lpattern(dash) lcolor(black))	 legend(off) mlabel mlabpo(12) mlabco(black) format(%3.2f)	


graph export output/figure4.pdf, as(pdf) replace

	
	
	
***********************************************************************
** Figure 5 treatment effects on vote intentino by patisan groups


areg vote_dpp_w1 T $Xs if dpp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store a	
areg vote_dpp_w1 T $Xs if mcp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store a1
areg vote_dpp_w1 T $Xs if utm_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store a2	


areg vote_mcp_w1 T $Xs if dpp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store b
areg vote_mcp_w1 T $Xs if mcp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store b1
areg vote_mcp_w1 T $Xs if utm_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store b2	

areg vote_utm_w1 T $Xs if dpp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store c
areg vote_utm_w1 T $Xs if mcp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store c1
reg vote_utm_w1 T $Xs if utm_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store c2
	
areg vote_udf_w1 T $Xs if dpp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store d
areg vote_udf_w1 T $Xs if mcp_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store d1
areg vote_udf_w1 T $Xs if utm_close==1,  absorb(ea_numeric)
	margins, at(T=0 T=1)
	est store d2


local x "ciopts(color(blue)) mcolor(blue) msymbol(S)  offset(0.25)"
local x1 "mcolor(green)  ciopts(color(green))  offset(0)"
local x2 "mcolor(red)  ciopts(color(red)) msymbol(D)  offset(-0.25)"
coefplot (a, label(DPP Supporters) `x' aseq("DPP")) (a1, label(MCP Supporters) `x1'  aseq("DPP")) (a2, label(UTM Supporters) `x2'  aseq("DPP"))  ///
	(b, label(DPP Supporters) `x' aseq("MCP")) (b1, label(MCP Supporters) `x1'  aseq("MCP")) (b2, label(UTM Supporters) `x2'  aseq("MCP"))  ///
		(c, label(DPP Supporters) `x' aseq("UTM")) (c1, label(MCP Supporters) `x1'  aseq("UTM")) (c2, label(UTM Supporters) `x2'  aseq("UTM")) ///
		(d, label(DPP Supporters) `x' aseq("UDF")) (d1, label(MCP Supporters) `x1'  aseq("UDF")) (d2, label(UTM Supporters) `x2'  aseq("UDF")) ///
	 ,  keep(T) title(" ", color(black) size(medsmall)) ///
		xline(0, lpattern(dash) lcolor(black))	mlabel mlabpo(12) mlabco(black) format(%3.2f) ///
		 aseq swapnames  ///
	graphr(color(white)) ytitle("Vote Choice", size(medsmall)) ///
	 ylabel(, labsize(medsmall) angle(horizontal)) xlabel(-.2(.05).2, labsize(medsmall)) ///
	 name(v1, replace) xtitle("Effect of Watching Debate", size(medsmall))    ///
	 legend(order(2 4 6) col(3))   levels(95)
		
	
graph export output/figure5.pdf, as(pdf) replace


***********************************************************************
** Figure 6 Performance assessment compared to pre-debate expectations
	

** Requires the long data

* Preserve data

tempfile wide
save `wide'

** Transform to long

** Create list of variables for transformation
local stub evalpost_w1_ evalpost_w2_ vote_w1_ vote_w2_ coethnic_w1_ coethnic_w2_ coethnic_ea_ close_ evaluation_ prior_  ///
	winner_all_ winner_district_ winner_expert_ performance_ performance_district_   ///
	confidence_w1_ confidence_w2_ str_policy_w1_ str_policy_w2_ qualified_w1_ qualified_w2_  ///
	trust_w1_ trust_w2_ incumbent_  prior_diff_dist_ goodnews_ ///
	danger_ reason_w1_ reason_w2_ campaign_ ea_close_ ea_close_majority_ friends_prop_ ///
	quota_agree_ fisp_agree_ immunity_agree_  
	


capture drop id
gen id = _n

reshape long `stub' , i(id) j(candidate)

gen party = "dpp" if candidate==1
replace party = "mcp" if candidate==2
replace party = "udf" if candidate==3
replace party = "utm" if candidate==4

gen prior = mcp_prior if party=="mcp"
	replace prior = udf_prior if party=="udf"
	replace prior = utm_prior if party=="utm"

	
* Diff Between Performance and Prior
gen prior_diff = 	performance_district_ - prior
label variable prior_diff "Performance minus Prior Expectations (Difference)"


** Create figure	
twoway (kdensity prior_diff if close_==1 , ytitle("Percent") graphr(color(white)) ///
	ylabel(, angle(horizontal)) color(gs1) 	 xline(0, lp(dot) lcolor(black)) ///
	xtitle("Performance minus Prior Expectations" , size(small))  ///
	title(" ", color(black) size(medium)) name(a, replace) ) ///	
	(kdensity prior_diff if close_==0&independent==0 , graphr(color(white)) ///
	ylabel(, angle(horizontal)) color(gs4) lp(dash) 	  ///
	xtitle("Performance minus Prior Expectations" , size(small))     ///
		legend(order(1 "Co-Partisan Candidates" 2 "Out-Party Candidates")))  

	
graph export output/figure6.pdf, as(pdf) replace
	
	
***********************************************************************
** Table 6 - describes variables

***********************************************************************
** Figure 7	 Effects on views about co- and out-partisans

** keep data in long format

* (A) policy strength

	
** Average, out-partisans
areg str_policy_w1_ T $Xs if close_==0&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store b

** Average co-partisans
areg str_policy_w1_ T $Xs if close_==1&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store c

** Average, out-partisans
areg str_policy_w2_ T $Xs if close_==0&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store b1

** Average co-partisans
areg str_policy_w2_ T $Xs if close_==1&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store c1	
	
local x "ciopts(color(gray)) mcolor(gray) msymbol(T)  offset(-0.15)"
local x1 "mcolor(black)  ciopts(color(black))  offset(0.15)"
coefplot  ///
 (b, `x1' label(After Debate)  aseq("Out-Partisans"))  (b1, `x'    aseq("Out-Partisans"))	///
 (c, `x1' aseq("Co-Partisans")) (c1, `x'  aseq("Co-Partisans"))  	///
	 ,  keep(T) title("(a) Strength of Policy Positions", color(black) size(medsmall)) ///
		xline(0, lpattern(dash) lcolor(black))	mlabel mlabpo(12) mlabco(black) format(%3.2f) ///
		 aseq swapnames  ///
	graphr(color(white))  ///
	 ylabel(, labsize(small) angle(horizontal)) xlabel(-.4(.1).4, labsize(small)) ///
	 name(v1, replace) xtitle("Effect of Watching Debate", size(small))    ///
	 legend(order(2 "After Debate" 4 "After Election"))   levels(95)
	
	
graph export output/figure7a.pdf, as(pdf) replace
	
	
** (B) Confidence in understanding of policy positions

** Average, out-partisans
areg confidence_w1_ T $Xs if close_==0&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store b

** Average co-partisans
areg confidence_w1_ T $Xs if close_==1&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store c

** Average, out-partisans
areg confidence_w2_ T $Xs if close_==0&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store b1

** Average co-partisans
areg confidence_w2_ T $Xs if close_==1&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store c1	
	
local x "ciopts(color(gray)) mcolor(gray) msymbol(T)  offset(-0.15)"
local x1 "mcolor(black)  ciopts(color(black))  offset(0.15)"
coefplot  ///
 (b, `x1' label(After Debate)  aseq("Out-Partisans"))  (b1, `x'    aseq("Out-Partisans"))	///
 (c, `x1' aseq("Co-Partisans")) (c1, `x'  aseq("Co-Partisans"))  	///
	 ,  keep(T) title("(b) Confidence in Understanding of Policy Positions", color(black) size(medsmall)) ///
		xline(0, lpattern(dash) lcolor(black))	mlabel mlabpo(12) mlabco(black) format(%3.2f) ///
		 aseq swapnames  ///
	graphr(color(white))  ///
	 ylabel(, labsize(small) angle(horizontal)) xlabel(-.4(.1).4, labsize(small)) ///
	 name(v1, replace) xtitle("Effect of Watching Debate", size(small))    ///
	 legend(order(2 "After Debate" 4 "After Election"))   levels(95)
	
	
graph export output/figure7b.pdf, as(pdf) replace
	
	
**** (c) Trust

	** Average, out-partisans
areg trust_w1_ T $Xs if close_==0&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store b

mean trust_w1_  if close_==0&independent==0	
	
** Average co-partisans
areg trust_w1_ T $Xs if close_==1&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store c

** Average, out-partisans
areg trust_w2_ T $Xs if close_==0&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store b1

** Average co-partisans
areg trust_w2_ T $Xs if close_==1&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store c1	
	
local x "ciopts(color(gray)) mcolor(gray) msymbol(T)  offset(-0.15)"
local x1 "mcolor(black)  ciopts(color(black))  offset(0.15)"
coefplot  ///
 (b, `x1' label(After Debate)  aseq("Out-Partisans"))  (b1, `x'    aseq("Out-Partisans"))	///
 (c, `x1' aseq("Co-Partisans")) (c1, `x'  aseq("Co-Partisans"))  	///
	 ,  keep(T) title("(c) Trust", color(black) size(medsmall)) ///
		xline(0, lpattern(dash) lcolor(black))	mlabel mlabpo(12) mlabco(black) format(%3.2f) ///
		 aseq swapnames  ///
	graphr(color(white))  ///
	 ylabel(, labsize(small) angle(horizontal)) xlabel(-.4(.1).4, labsize(small)) ///
	 name(v1, replace) xtitle("Effect of Watching Debate", size(small))    ///
	 legend(order(2 "After Debate" 4 "After Election"))   levels(95)
	
	
graph export output/figure7c.pdf, as(pdf) replace
	
	
**** (d) QUualifications
	
	** Average, out-partisans
areg qualified_w1_ T $Xs if close_==0&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store b

** Average co-partisans
areg qualified_w1_ T $Xs if close_==1&independent==0, vce(cluster id) absorb(ea_numeric)
	estimates store c

** Average, out-partisans
areg qualified_w2_ T $Xs if close_==0&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store b1

** Average co-partisans
areg qualified_w2_ T $Xs if close_==1&independent==0&wave2==1, vce(cluster id) absorb(ea_numeric)
	estimates store c1	
	
local x "ciopts(color(gray)) mcolor(gray) msymbol(T)  offset(-0.15)"
local x1 "mcolor(black)  ciopts(color(black))  offset(0.15)"
coefplot  ///
 (b, `x1' label(After Debate)  aseq("Out-Partisans"))  (b1, `x'    aseq("Out-Partisans"))	///
 (c, `x1'   aseq("Co-Partisans")) (c1, `x'  aseq("Co-Partisans"))  	///
	 ,  keep(T) title("(d) Qualifications", color(black) size(medsmall)) ///
		xline(0, lpattern(dash) lcolor(black))	mlabel mlabpo(12) mlabco(black) format(%3.2f) ///
		 aseq swapnames  ///
	graphr(color(white))  ///
	 ylabel(, labsize(small) angle(horizontal)) xlabel(-.4(.1).4, labsize(small)) ///
	 name(v1, replace) xtitle("Effect of Watching Debate", size(small))    ///
	 legend(order(2 "After Debate" 4 "After Election"))   levels(95)
	
	
graph export output/figure7d.pdf, as(pdf) replace

**************************
** Re-open wide data

use `wide', clear



***************************************************************
** Figure 8 Persuasion, Impacts on policy preferences


capture gen opposition = 0
replace opposition =1 if mcp_close==1|udf_close==1|utm_close==1

capture gen p3 = 1 if dpp_close==1
	replace p3 = 2 if opposition==1
	replace p3 = 3 if independent ==1
label define p3 1 "Incumbent" 2 "Opposition" 3 "Independents", replace
label values p3 p3

** pooled policy agreement
gen agree = (quota_remove+immunity_remove+fisp_remove)/3
tab agree



areg agree T##i.p3 $Xs if wave2==1,  absorb(ea_numeric)
	margins, at( p3=1 p3=2 p3=3 T=0 T=1)
	mplotoffset, graphr(color(white)) ylabel(, angle(horizontal))  ///
		xscale(range(0.5 3.5)) title("", color(black) size(medsmall)) xtitle("Partisanship") level(95) ///
		plot2opts(msymbol(C) mcolor(black)) plot1opts(msymbol(T) mcolor(gray)) ///
		ytitle("Predicted Proportion of Policies Agreed", size(medsmall)) recast(scatter) name(a, replace)

		* Code for treatment effects in each group and associated p-values
		* hand added to the figure
		margins, at( p3=1 p3=2 p3=3 ) dydx(T)
	
		
graph export output/figure8.pdf, as(pdf) replace
* Graph is adjusted using PDF editor to add treatment effects and p-values	

areg quota_remove Ed_T##i.p3  $Xs if wave2==1,  absorb(ea_numeric)

areg fisp_remove Ag_T##i.p3  $Xs if wave2==1,  absorb(ea_numeric)

areg immunity_remove Ag_T##i.p3  $Xs if wave2==1,  absorb(ea_numeric)
